<!--  -->
<template>
  <div class="border">
    <div class="head">
      <span class="title">股权质押市场概况</span>
    </div>
    <div class="flex column">
      <div class="flex grow">
        <div class="flex grow column" style="width: 574px">
          <div class="head sub-head">
            <span class="title"
              >股权质押走势图（数据来源：中登公司）<i class="icon"></i
              ><span class="txt"
                ><i class="arrow"></i
                >A股质押总比例含义是A股所有质押股份市值与A股总市值的比</span
              ></span
            >
          </div>
          <div ref="lineChart" style="height: 251px"></div>
        </div>
        <div class="flex grow column" style="width: 574px">
          <div class="head sub-head">
            <span class="title"
              >股权质押比例分布一览（数据来源：中登公司）</span
            >
          </div>
          <div ref="barChart" style="height: 251px">Loading...</div>
        </div>
      </div>
    </div>
    <table>
      <thead>
        <tr>
          <td>交易日期</td>
          <td>A股质押总比例(%)</td>
          <td>质押公司数量</td>
          <td>质押笔数</td>
          <td>质押总股数(股)</td>
          <td>质押总市值(元)</td>
          <td>沪深300指数</td>
          <td>涨跌幅</td>
        </tr>
      </thead>
      <tbody>
        <slot></slot>
      </tbody>
    </table>
  </div>
</template>

<script>
import { getChart } from "../api/index";
import drawLine from "../script/drawLine";
import drawBar from "../script/drawBar";
export default {
  data() {
    return { brief: [], rate: [] };
  },

  components: {},

  computed: {},

  mounted() {
    this.getChart();
  },

  methods: {
    async getChart() {
      await getChart().then((back) => {
        if (back.status == 1) {
          let brief = back.data.brief;
          this.brief = brief.reverse();
          this.rate = back.data.rate;
          this.lineChart();
          this.barChart();
        }
      });
    },
    lineChart() {
      drawLine({
        container: this.$refs.lineChart,
        data: this.brief,
      });
    },
    barChart() {
      drawBar({
        container: this.$refs.barChart,
        data: this.rate,
      });
    },
  },
};
</script>
<style lang="scss" scoped>
@import "../style/var.scss";
.border {
  border: 2px solid $border;
  border-radius: 6px;
}
.head {
  background: $border;
  line-height: 34px;
  text-align: center;
  position: relative;
  &.sub-head {
    border: 1px solid $bg;
    .title {
      font-size: 16px;
      position: relative;
      color: #e6e6e6;
      .icon {
        display: inline-block;
        width: 16px;
        height: 16px;
        position: relative;
        top: 3px;
        background: url($PIC_URL + "/tlbypcWeb/pledge/sm.png") no-repeat;

        background-size: 100%;
        cursor: pointer;
        &:hover + .txt {
          display: inline-block;
        }
      }
      .txt {
        display: none;
        width: max-content;
        z-index: 2;
        position: absolute;
        font-size: 13px;
        color: #ff8a00;
        background: #27282e;
        border: 1px solid #000000;
        padding: 4px 10px;
        line-height: initial;
        top: 26px;
        right: -349px;
        &:before {
          box-sizing: content-box;
          width: 0px;
          height: 0px;
          position: absolute;
          top: -8px;
          left: 12px;
          padding: 0;
          border-bottom: 4px solid #27282e;
          border-top: 4px solid transparent;
          border-left: 4px solid transparent;
          border-right: 4px solid transparent;
          display: block;
          content: "";
          z-index: 12;
        }
        &:after {
          box-sizing: content-box;
          width: 0px;
          height: 0px;
          position: absolute;
          top: -10px;
          left: 11px;
          padding: 0;
          border-bottom: 5px solid #000000;
          border-top: 5px solid transparent;
          border-left: 5px solid transparent;
          border-right: 5px solid transparent;
          display: block;
          content: "";
          z-index: 10;
        }
        // .arrow {
        //   display: inline-block;
        //   //   width: 5px;
        //   //   height: 5px;
        //   //   padding: 8px;
        //   background-color: #ffffff;
        //   border: #cccccc solid 1px;
        //   //   border-radius: 3px;

        // }
      }
    }
  }
  .title {
    font-size: 18px;
    color: #ff4e39;
    font-weight: 400;
  }
}
table {
  width: 100%;
  color: #bcbfc4;
  font-size: 15px;
  text-align: center;
  line-height: 20px;
  // table-layout: fixed;
  td {
    padding: 6px 0;
  }
  thead {
    background: #1c1d21;
    td {
      border: 1px solid #323337;
    }
  }
  tbody {
    td {
      border: 1px solid #25262a;
      &.red {
        color: #ea2827;
      }
      &.green {
        color: #31ed24;
      }
    }
    tr:nth-of-type(2n) {
      background: #111117;
    }
  }
}
.lookMore {
  text-align: right;
  line-height: 36px;
  font-size: 16px;
  color: #e6e6e6;
  margin-bottom: 4px;
  .txt {
    cursor: pointer;
    &:hover {
      color: #ff4e39;
    }
  }
}
</style>
